package com.acensi.guy.multithreading.synchroniser.semaphore;

public class Client extends Thread {
	private AtmMachines machines ;      
	private static long SLEEP_DURATION = 50000;
	private long debut ;
	private long fin ;
			
	public Client(AtmMachines machine, String name){
		this.machines = machine ;
		this.setName(name);
		this.start();
		this.debut = System.currentTimeMillis(); 	
	}


	public void run(){
		try{				
			System.out.println(getName() + " waiting to access ATM machine\n") ;
			machines.acquire();

			Thread.sleep(SLEEP_DURATION);  
			System.out.println(getName() + " is done accessing ATM machine\n") ;
			machines.release();
			this.fin = System.currentTimeMillis();
			long duration  = this.fin - this.debut ;  
			
			System.out.println("duration for:  " + getName() + " = " + duration);

		}catch(InterruptedException ie){
			ie.printStackTrace();
		}

	}

}
